* Table 1: Characteristics of applicants' ROLs

********************************************************************************
************************** Prepare data ****************************************
********************************************************************************

clear all
use id rank mp mp1 pref_for_location pref_for_uni pref_for_faculty pref_for_field pref_for_major using "${data_rols}", clear

merge 1:1 id using "${data_students}", keepusing(funded_only unfunded_only disadv)

label variable mp "Same study program consecutively (anywhere on ROL)"
label variable mp1 "Same study program consecutively on the top of the ROL"

lab var funded_only "State-funded contract exclusively"
lab var unfunded_only "Self-funded contract exclusively"

gen state_funded_and_self_funded = 1 - funded_only - unfunded_only
lab var state_funded_and_self_funded "State- and self-funded contracts"


* Prepare Table 1
cap file close sumstat
file open sumstat using "${table1}", write replace
file write sumstat "\begin{tabular}{l S[table-number-alignment = center-decimal-marker] S[table-number-alignment = center-decimal-marker] S[table-number-alignment = center-decimal-marker] S[table-number-alignment = center-decimal-marker]} \\ \hline\hline" _n
file write sumstat " & \multicolumn{1}{c}{{\parbox{2.1cm}{\centering All applicants (\%)}}} & \multicolumn{1}{c}{{\parbox{2.1cm}{\centering Non-disadvantaged (\%)}}} & \multicolumn{1}{c}{{\parbox{2.1cm}{\centering Disadvantaged (\%)}}} & \multicolumn{1}{c}{{\parbox{2.1cm}{\centering p-value ((2)=(3))}}} \\ " _n
file write sumstat " & \multicolumn{1}{c}{(1)} & \multicolumn{1}{c}{(2)} & \multicolumn{1}{c}{(3)} & \multicolumn{1}{c}{(4)} \\ \hline" _n

file write sumstat " \multicolumn{5}{l}{A. {\it Preference for funding}} \\ " _n
local vars funded_only unfunded_only state_funded_and_self_funded mp mp1
foreach var of varlist `vars' {
	local lab_var: variable label `var'
	quietly: sum `var'
	local stat_mean: 	display %4.1f r(mean)*100
	
	forvalues i = 0/1 {
		quietly: sum `var' if disadv == `i'
		local stat_mean`i': 	display %4.1f r(mean)*100
	}
	
	qui reg `var' disadv, r
	local diff_mixed_treat_p: 		display %4.2f (2 * ttail(e(df_r), abs(_b[disadv]/_se[disadv])))
	
	file write sumstat " {\parbox{6.5cm}{`lab_var'}} & `stat_mean' & `stat_mean0' & `stat_mean1' &  `diff_mixed_treat_p' \\ " _n
}

file write sumstat " \multicolumn{5}{c}{} \\ " _n
file write sumstat " \multicolumn{5}{l}{B. {\it Preference for program characteristics}} \\ " _n

local vars pref_for_location pref_for_uni pref_for_faculty pref_for_field pref_for_major
foreach var of varlist `vars' {
	local lab_var: variable label `var'
	quietly: sum `var'
	local stat_mean: 	display %4.1f r(mean)*100
	forvalues i = 0/1 {
		quietly: sum `var' if disadv == `i'
		local stat_mean`i': 	display %4.1f r(mean)*100
	}
	
	qui reg `var' disadv, r
	local diff_mixed_treat_p: 		display %4.2f (2 * ttail(e(df_r), abs(_b[disadv]/_se[disadv])))
	
	file write sumstat " {\parbox{6.5cm}{`lab_var'}} & `stat_mean' & `stat_mean0' & `stat_mean1' &  `diff_mixed_treat_p' \\ " _n
}

	count
	local count_total: display %12.0fc r(N)
	count if disadv == 0
	local count_total0: display %12.0fc r(N)
	count if disadv == 1
	local count_total1: display %12.0fc r(N)
	
file write sumstat "\hline \multicolumn{1}{l}{\# of applicants} & \multicolumn{1}{c}{`count_total'} & \multicolumn{1}{c}{`count_total0'} & \multicolumn{1}{c}{`count_total1'} & \\ " _n

file write sumstat "\hline\hline \multicolumn{5}{p{17cm}}{{\it Notes}: Panel A focuses on preference for funding. Specifically, Panel A shows the share of applicants who rank state-funded (self-funded) contracts exclusively, the share of students who both rank state-funded and self-funded contracts, and the share of applicants who rank the same study program with state-funding and self-funding consecutively anywhere on the ROL, and who rank the same study program with state-funding and self-funding consecutively on the top of the ROL. Panel B focuses on preference for program characteristics. Specifically, Panel B shows the share of applicants who rank exclusively contracts that are in the same settlement (single program location), at a single university (single university), and at a single faculty of a university (single university), and the share of applicants who rank exclusively contracts in a single field of study, and in a single major. Columns (2) and (3) report these shares for non-disadvantaged and disadvantaged applicants, respectively. We test whether these shares differ between disadvantaged and non-disadvantaged applicants. Column (4) reports the corresponding p-values.}"
file write sumstat "\end{tabular}" _n
file close sumstat